// packageA/pages/redpacket-detail/redpacket-detail.js

import {check} from '../../../util/identityCheck'
import {RedPacket} from '../../../models/redpacket'

let packetModel = new RedPacket()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showLoading: false,
    data: [],
    page: 1
  },

  onShow () {
    if(!check())return
  },

  onLoad (options) {
    this.getPacketDetail()
  },

  getPacketDetail (type) {
    packetModel.getPacketDetail({
      page: this.data.page
    }, res => {
      this.setData({
        data: type == 'more' ? [...this.data.data, ...res.rows] : res.rows,
        showLoading: res.rows.length >= 10
      })
    })
  },

  onReachBottom () {
    this.setData({
      page: this.data.page + 1
    })
    this.getPacketDetail('more')
  }
})
